using Assets.Scripts.GDK;
using UnityEngine;

namespace Brick
{
	public class StorePanel : gdk_base_panel
	{
		public RectTransform scrollContent;

		public RectTransform rowItemBox;

		public override void OnLoad()
		{
			initData();
			gdk_game_manager.AddEventListener(EventID.BALLCHANGE, updateBall);
		}

		public override void UnLoad()
		{
			gdk_game_manager.RemoveEventListener(EventID.BALLCHANGE, updateBall);
		}

		public override void OnStart()
		{
		}

		public void onShowEvent()
		{
			initData();
			base.gameObject.SetActive(value: true);
		}

		public void onHideEvent()
		{
			base.gameObject.SetActive(value: false);
		}

		public void initData()
		{
			rowItemBox.gameObject.SetActive(value: true);
			gdk_utils.removeAllChildren(scrollContent);
			int useBallIndex = GameData.useBallIndex;
			PiFuModel[] piFuArray = GameData.piFuArray;
			Debug.Log(GameData.piFuArray);
			for (int i = 0; i < piFuArray.Length; i++)
			{
				PiFuModel pifumd = piFuArray[i];
				RectTransform rectTransform = Object.Instantiate(rowItemBox);
				rectTransform.gameObject.SetActive(value: true);
				rectTransform.SetParent(scrollContent, worldPositionStays: false);
				rectTransform.GetComponent<StoreItem>().OnData(i, pifumd, "��С:14mm", useBallIndex);
			}
			rowItemBox.gameObject.SetActive(value: false);
		}

		public void updateBall()
		{
			StoreItem[] componentsInChildren = scrollContent.GetComponentsInChildren<StoreItem>();
			foreach (StoreItem storeItem in componentsInChildren)
			{
				storeItem.ReUsed();
			}
		}

		public void OnCloseClick()
		{
			gdk_game_manager.PlaySound(AudioID.click);
			close();		
		}
	}
}

